import json
from itertools import count

from django.views.generic.base import View
from apps.blog.models import Collect,city


class MapListView(View):
    def get(self,request):
        json_list1=[]
        json_list2=[]
        collets = Collect.objects.all()
        for collet in collets:
            json_dict1={}
            json_dict1["name"] = collet.type
            json_dict1["children"] = json_list1
            json_list2.append(json_dict1)
            json_dict={}
            json_dict["name"] = collet.city
            json_dict['value'] = '['+collet.location+']'
            json_dict['value']=json.loads(json_dict['value'])
            json_list1.append(json_dict)

        from django.http import HttpResponse
        return HttpResponse(json.dumps(json_list2),content_type="application/json")


class HotView(View):
    def get(self,request):
        json_list1=[]
        json_list2=[]
        json_list3=[]
        collets = Collect.objects.all()
        for collet in collets:
            json_dict1={}
            json_dict1["name"] = collet.type
            json_dict1["children"] = json_list2
            json_list1.append(json_dict1)
            json_dict2={}
            json_dict2["name"] = collet.name
            json_dict2['value'] = collet.stock
            # json_dict2['value']=json.loads(json_dict2['value'])
            json_dict2['clildren'] = json_list3
            json_list2.append(json_dict2)
            json_dict3={}
            json_dict3["name"] = collet.name
            json_dict3["value"] = collet.value
            json_list3.append(json_dict3)

        from django.http import HttpResponse
        return HttpResponse(json.dumps(json_list1),content_type="application/json")


class TrendView(View):
    def get(self,request):
        collets = Collect.objects.all()
        json_dict = {}
        dict = {}
        dict1 = {}
        dict2 = {}
        dict3 = {}
        list = []
        list1 = []
        list2 = []
        list3 = []
        dict_list = []
        dict_list1 = []
        dict_list2 = []
        json_dict["map"] = dict
        dict["title"] = "地区产量趋势"
        dict['base'] = 310
        dict['unit'] = "万"
        dict['data'] = list
         #成都
        dict1['name'] = '四川'
        dict_list = ["155.13","154.65","171.46","164.38","237.23","300.65","240.29","232.07","193.31","136.70","48.64","90.20"]
        dict1['data'] = dict_list
        list.append(dict1)
        #丽江
        dict2['name'] = ['贵州']
        dict_list1 = ["86.25","33.80","145.58","21.79","176.09","132.41","291.05","191.89","151.54","94.25","141.75","157.14"]
        dict2['data'] = dict_list1
        list.append(dict2)
        #乐山
        dict3['name'] = ['云南']
        dict_list2 = ["143.94","186.29","183.64","251.48","195.48","152.16","52.47","184.12","203.79","39.16","56.37","161.64"]
        dict3['data'] = dict_list2
        list.append(dict3)

        #seller
        s_dict = {}
        s1_dict={}
        s2_dict = {}
        s3_dict = {}
        json_dict["seller"] = s_dict
        s_dict["title"] = "各地产量趋势"
        s_dict['base'] = 120
        s_dict['unit'] = "万"
        s_dict['data'] = list
        s1_dict['name'] = '成都'
        dict_list = ["155.13","154.65","171.46","164.38","237.23","300.65","240.29","232.07","193.31","136.70","48.64","90.20"]
        s1_dict['data'] = dict_list
        list2.append(s1_dict)
        #丽江
        s2_dict['name'] = '丽江'
        dict_list1 = ["86.25","33.80","145.58","21.79","176.09","132.41","291.05","191.89","151.54","94.25","141.75","157.14"]
        s2_dict['data'] = dict_list1
        list2.append(s2_dict)
        #乐山
        s3_dict['name'] = '乐山'
        dict_list2 = ["143.94","186.29","183.64","251.48","195.48","152.16","52.47","184.12","203.79","39.16","56.37","161.64"]
        s3_dict['data'] = dict_list2
        list2.append(s3_dict)

        #药植物产量趋势
        c_dict = {}
        c1_dict={}
        c2_dict = {}
        c3_dict = {}
        json_dict["commodity"] = c_dict
        c_dict["title"] = "各地产量趋势"
        c_dict['base'] = 120
        c_dict['unit'] = "万"
        c_dict['data'] = list
        c1_dict['name'] = '藏药'
        dict_list = ["47.71","13.34","19.30","7.93","41.93","23.01","22.63","26.91","0.62","39.23","48.74","29.48"]
        c1_dict['data'] = dict_list
        list3.append(c1_dict)
        #丽江
        c2_dict['name'] = '羌药'
        dict_list1 = ["46.66","46.52","23.65","1.73","44.26","47.07","17.86","40.20","3.78","31.46","28.01","8.63"]
        c2_dict['data'] = dict_list1
        list3.append(c2_dict)
        #乐山
        s3_dict['name'] = '彝药'
        dict_list2 = ["26.98","30.71","42.59","29.50","26.86","17.65","30.15","15.85","9.28","30.20","32.35","34.46"]
        s3_dict['data'] = dict_list2
        list3.append(c3_dict)

        #commen
        co_dict = {}
        json_dict["common"] = co_dict
        co_dict['month'] = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]

        #type
        t_dict = {}
        t_list = []
        t1_dict = {}
        t2_dict = {}

        json_dict["type"] = t_list
        t_dict['key'] = 'map'
        t_dict['text'] = '地区产量趋势'
        t_list.append(t_dict)
        t1_dict['key'] = 'seller'
        t1_dict['text'] = '地区产量趋势'
        t_list.append(t1_dict)
        t2_dict['key'] = 'commodity'
        t2_dict['text'] = '地区产量趋势'
        t_list.append(t2_dict)




        #
        # json_list1 = json_dict1
        # json_dict1["seller"] = json_list4
        # json_dict4={}
        # json_dict4['title'] = "各地产量趋势"
        # json_dict4['base'] = 120
        # json_dict4['unit'] = "万"
        # json_dict4['data'] = list1
        # json_list3 = json_dict4
        # json_dict5={}
        # for collect in collets:
        #     json_dict5["name"] = collect.city
        #     json_dict5["value"] = []
        #     list1 = json_dict5
        # json_list1 = json_list3

        from django.http import HttpResponse
        return HttpResponse(json.dumps(json_dict),content_type="application/json")